<?php
if (!defined('IN_IA')) {
    exit('Access Denied');
}
//chemeng
class Unlimited_EweiShopV2Page extends PluginWebPage
{

    public function log()
    {
        global $_W;
        global $_GPC;
        $pindex = max(1, intval($_GPC['page']));
        $psize = 20;
        $condition = ' and log.uniacid=:uniacid ';

        $params = array(':uniacid' => $_W['uniacid']);

        if (!empty($_GPC['keyword'])) {
            $_GPC['keyword'] = trim($_GPC['keyword']);

            $condition .= ' and (m.realname like :keyword or m.nickname like :keyword or m.mobile like :keyword or o.ordersn like :keyword )';

            $params[':keyword'] = '%' . $_GPC['keyword'] . '%';
        }

        if (empty($starttime) || empty($endtime)) {
            $starttime = strtotime('-1 month');
            $endtime = time();
        }

        if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
            $starttime = strtotime($_GPC['time']['start']);
            $endtime = strtotime($_GPC['time']['end']);
            $condition .= ' AND log.createtime >= :starttime AND log.createtime <= :endtime ';
            $params[':starttime'] = $starttime;
            $params[':endtime'] = $endtime;
        }

        $sql = 'select log.*,m.nickname,m.id as mid,m.avatar,m.realname,m.mobile,o.ordersn,o.status as ostatus from ' . tablename('ewei_shop_unlimited_commission') . ' log  left join ' . tablename('ewei_shop_member') . ' m on m.openid = log.openid and m.uniacid = log.uniacid left join '.tablename('ewei_shop_order').' o on o.id = log.orderid  where 1 ' . $condition . ' ORDER BY log.createtime DESC ';

        if (empty($_GPC['export'])) {
            $sql .= 'LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
        }

        $list = pdo_fetchall($sql, $params);


        if (!empty($list)) {
            foreach ($list as &$row) {

                if ($row['ostatus'] == -1) {
                    $row['ostatusstr'] = '订单已关闭';
                }else if($row['ostatus'] == 1){
                    $row['ostatusstr'] = '订单已支付';
                }else if($row['ostatus'] == 2){
                    $row['ostatusstr'] = '订单已发货';
                }else if($row['ostatus'] == 3){
                    $row['ostatusstr'] = '订单已收货';
                }
                if ($row['status'] == 0) {
                    $row['statusstr'] = '未打款';
                }else if($row['status'] == 1){
                    $row['statusstr'] = '已打款';
                }
            }
            unset($row);
        }

        $total = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_unlimited_commission') . ' log  left join ' . tablename('ewei_shop_member') . ' m on m.openid = log.openid  where 1 ' . $condition , $params);
        $pager = pagination2($total, $pindex, $psize);

        include $this->template();
    }
}

?>
